/*
    17. Write a program in C to remove characters in String Except Alphabets. 

    Test Data :
    Input the string : w3resource.com

    Expected Output :

    After removing the Output String : wresourcecom
*/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define MAX_LEN 1024

char* getstr(char *str)
{
    char ch;
    char *p = str;
    while((ch = getchar()) != '\n'){
        *p = ch;
        p++;
    }
    *p = '\0';
    return str;
}

int getstrlen(char *str)
{
    int len = 0;
    char *p = str;
    while(*p != '\0'){
        len++;
        p++;
    }
    len++; // '\0'
    return len;
}

char *removeother(char *str)
{
    int len = getstrlen(str);
    char *p = malloc(len);
    char *tmp = p;
    while(*str){
        if(isalpha(*str)){
            *p++ = *str;
        }
        str++;
    }
    *p = '\0';
    return tmp;
}

int main(void)
{
    char *str = malloc(MAX_LEN);
    printf("Input the string : ");
    getstr(str);
    printf("After removing the output string : %s", removeother(str));

    return 0;
}